/**
 * Created by xk on 2017/7/26 0026.
 */


/**
 * 生成一个多线图需要的option对象
 * @param attrMap
 * @param data
 * @returns {{tooltip: {trigger: string}, legend: {data: Array}, grid: {left: string, right: string, bottom: string, containLabel: boolean}, toolbox: {feature: {saveAsImage: {}}}, xAxis: {type: string, boundaryGap: boolean, data: Array}, yAxis: {type: string}, series: Array}}
 */
function getLine(attrMap, data) {
    var legend_arr =[];
    var x_arr = [];//x轴
    var series_arr = [];
    for(i = 0; i < attrMap.lines.length; i++){
        legend_arr.push(attrMap.lines[i].name);
        //每条线初始化
        series_arr.push(
            {
                name: legend_arr[i],
                type: 'line',
                data: []
            }
        );
    }

    if(data && data.length > 0){
        for(i = 0; i < data.length; i++){
            x_arr.push(data[i][attrMap.xAttr]);

            //给线赋值
            for(j = 0; j < attrMap.lines.length; j++){
                legend_arr.push(attrMap.lines[j].name);
                //每条线初始化
                series_arr[j].data.push(data[i][attrMap.lines[j].attr]);
            }

        }
    }

    var option = {
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: legend_arr
        },
        grid: {
            left: '1%',
            right: '3%',
            bottom: '1%',
            containLabel: true
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: x_arr
        },
        yAxis: {
            type: 'value'
        },
        series: series_arr
    };
    return option;
}
